package org.deltaset.meta.internal;

import org.deltaset.meta.TitleResolver;

/**
 *
 * @author dmakariev
 */
class TitleResolverImpl implements TitleResolver {

    @Override
    public String modelTitle(Object model) {
        if (null == model) {
            return null;
        }
        if (model.getClass().isEnum()) {
            return model.toString();
        }
        final String titleMethodName = "title";
        if (ReflectionUtils.hasMethod(model.getClass(), String.class, titleMethodName)) {
            return (String) ReflectionUtils.executeMethod(model, titleMethodName);
        }
        //it is following NakedObjects convention for title method. 
        return model.toString();
    }
}
